// pages/coach/detail/detail.js
var common = require('../../../utils/common.js');
Page({
  data: {
    detail: {},
    tapHide: [false, true, true],
    tapActive: ['tab-active', '', ''],
    evaluates: [],
    message: [],
  },
  id: 0,
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.id = options.id;
    this.reqDetail();
  },
  reqDetail: function () {
    var that = this;
    common.asynPost(common.API.coach.detail, {
      id: that.id
    }, function (data) {
      var attributes = [];
      var items = data['detail'].attributeItems || [];
      for (var i = 0; i < items.length;) {
        var temp = [items[i++]];
        if (i < items.length) {
          temp.push(items[i++]);
        }
        attributes.push(temp);
      }
      data['detail'].attributeItems = attributes;
      that.setData({ detail: data['detail'] });
    });
  },
  coachIntro: function (event) {
    this.setData({
      tapActive: ['tab-active', '', ''],
      tapHide: [false, true, true]
    });
  },
  coachEvalute: function () {
    var self = this;
    self.setData({
      tapActive: ['', 'tab-active', ''],
      tapHide: [true, false, true]
    });
    self.reqEvaluates();
  },
  coachMessage: function () {
    var self = this;
    self.setData({
      tapActive: ['', '', 'tab-active'],
      tapHide: [true, true, false]
    });
  },
  reqEvaluates: function () {
    var self = this;
    common.asynPost(common.API.coach.evaluates, {
      id: self.id,
      skip: 0,
      take: 10
    }, function (data) {
      self.setData({
        evaluates: data['evaluates']
      });
    });
  },
  messageClick: function () {
    wx.showModal({
      title: '提示',
      content: '正在研发中...',
      showCancel: false,
      success: function (res) {
      }
    })
  },
  nowApply: function () {
    wx.navigateTo({
      url: '../book/book?id=' + this.id + '&price=' + this.data.detail.money + '&typeName=' +this.data.detail.typeName + '&coachName=' + this.data.detail.name
    });
  },
  onShareAppMessage() {
    return {
      title: this.data.detail['typeName'],
      desc: this.data.detail['intro'],
      path: 'pages/coach/detail/detail?id=' + this.data.detail.id
    }
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})